package com.jwds.digital.bios.business.core.infrastructure.dto.belt.assembler;

import com.jwds.digital.bios.business.core.infrastructure.dto.belt.BeltRouteInfoReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.vo.belt.BeltRouteInfoRespVO;
import com.jwds.digital.bios.business.core.infrastructure.entity.belt.BeltRouteInfo;
import java.util.Objects;

/**
 * BeltRouteInfo DTO与Entity之间的相互转换
 *
 * @author 林柏云
 * @date 2024-10-24
 */
public class BeltRouteInfoAssembler {

  /**
  * 将传输对象转换为实体对象
  *
  * @param dto 传输对象
  * @return 实体对象
  */
  public static BeltRouteInfo dto2entity(BeltRouteInfoReqDTO dto)  {
    if (dto == null) {
      return null;
    }
    BeltRouteInfo entity = new BeltRouteInfo();
    entity.setRouteName(dto.getRouteName());
    entity.setRouteLength(dto.getRouteLength());
    return entity;
  }

  /**
  * 将传输对象转换为实体对象
  *
  * @param dto 传输对象
  * @param entity 原实体对象
  * @return 实体对象
  */
  public static BeltRouteInfo dto2entity(BeltRouteInfoReqDTO dto, BeltRouteInfo entity){
    if (dto == null) {
      return null;
    }
    if(Objects.nonNull(dto.getRouteName())) {
      entity.setRouteName(dto.getRouteName());
    }
    if(Objects.nonNull(dto.getRouteLength())) {
      entity.setRouteLength(dto.getRouteLength());
    }
    return entity;
  }

  /**
  * 将实体对象转换为传输对象
  *
  * @param entity 实体对象
  * @return 传输对象
  */
  public static BeltRouteInfoRespVO entity2dto(BeltRouteInfo entity) {
    if (entity == null) {
      return null;
    }
    BeltRouteInfoRespVO dto = new BeltRouteInfoRespVO();
    dto.setId(entity.getId());
    dto.setRouteName(entity.getRouteName());
    dto.setRouteLength(entity.getRouteLength());
    dto.setCreateUser(entity.getCreateUser());
    dto.setCreateTime(entity.getCreateTime());
    dto.setModifyUser(entity.getModifyUser());
    dto.setModifyTime(entity.getModifyTime());
    return dto;
  }

}
